/**
 * Copyright 2009-2019 the original author or authors.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.ibatis.session;

import java.sql.Connection;

/**
 * Creates an {@link SqlSession} out of a connection or a DataSource
 * 从connection或者DataSource中创建一个{@link SqlSession}
 *
 * @author Clinton Begin
 * @see SqlSessionFactoryBuilder
 */
public interface SqlSessionFactory {

  /**
   * 获取{@link SqlSession}
   *
   * @return
   */
  SqlSession openSession();

  /**
   * 获取{@link SqlSession}
   *
   * @param autoCommit 设置是否自动提交
   * @return
   */
  SqlSession openSession(boolean autoCommit);

  /**
   * 通过{@link Connection}获取{@link SqlSession}
   *
   * @param connection
   * @return
   */
  SqlSession openSession(Connection connection);

  /**
   * 获取{@link SqlSession}
   *
   * @param level 设置事务隔离级别,隔离级别的类型在{@link TransactionIsolationLevel}中
   * @return
   * @see TransactionIsolationLevel
   */
  SqlSession openSession(TransactionIsolationLevel level);

  /**
   * 根据执行器类型获取{@link SqlSession}
   *
   * @param execType 执行器类型{@link ExecutorType}
   * @return
   */
  SqlSession openSession(ExecutorType execType);

  /**
   * 获取{@link SqlSession}
   *
   * @param execType   执行器类型
   * @param autoCommit 是否自动提交
   * @return
   */
  SqlSession openSession(ExecutorType execType, boolean autoCommit);

  /**
   * 获取{@link SqlSession}
   *
   * @param execType 执行器类型
   * @param level    事务隔离级别
   * @return
   */
  SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level);

  /**
   * 获取{@link SqlSession}
   *
   * @param execType   执行器类型
   * @param connection JDBC链接
   * @return
   */
  SqlSession openSession(ExecutorType execType, Connection connection);

  /**
   * 获取全局配置{@link Configuration}
   *
   * @return
   */
  Configuration getConfiguration();

}
